﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Data;

namespace WebSys.UI.Control.ZhengShou
{
    public class ProjectBJInfoControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        public string userid = string.Empty;
        public string id = string.Empty;
        TextBox proName, proSM;
        CheckBox isBj;
        Button BtnSave;
        protected override void OnLoad(EventArgs e)
        {
            if (HttpContext.Current.Session["UserID"] == null)
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            }
            else
            {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            InitControl();
            id = base.Page.Request["ID"];
            base.OnLoad(e);
            if (!base.Page.IsPostBack)
            {
                Bind();
            }
            IsLookPerson();
        }


        private void IsLookPerson()
        {
            string sql = "Select rolename from zs_role where id in (Select roleid from zs_user_in_role where userid = '" + userid + "')";
            DataTable dt = _EluZSDataProvider.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (dt.Rows[i]["rolename"].ToString().Equals("查看人员"))
                    {
                        Button btnSave = (Button)FindControl("btnSave");
                        btnSave.Visible = false;
                    }
                }
            }
        }

        protected void InitControl()
        {
            proName = (TextBox)FindControl("proName");
            proSM = (TextBox)FindControl("proSM");
            isBj = (CheckBox)FindControl("isBj");
            BtnSave = (Button)FindControl("BtnSave");
            BtnSave.Click += new EventHandler(BtnSave_Click);
        }


        protected void Bind()
        {
           
            string sql = string.Format("Select 项目名称,报结状态,报结说明 from zs_project where id = '{0}'",id);
            DataTable dt = _EluZSDataProvider.GetDTTable(sql);
            if (dt.Rows.Count>0)
            {
                proName.Text = dt.Rows[0]["项目名称"].ToString();
                proSM.Text = dt.Rows[0]["报结说明"].ToString();
                if (dt.Rows[0]["报结状态"].ToString().Equals("1"))
                {
                    isBj.Checked = true;
                }
            }
        }

        protected void BtnSave_Click(object sender, EventArgs e)
        {
            int bj = 0;
            if (isBj.Checked)
            {
                bj = 1;
            }
            string sql = string.Format("update zs_project set 报结状态 = '{0}',报结说明 = '{1}' where id = '{2}' ",bj,proSM.Text,id);
            _EluZSDataProvider.RunSqlNon(sql);
            Page.ClientScript.RegisterStartupScript(this.GetType(), "1", "<script>alert('保存成功！');location.href = 'ProjectBJ.aspx';</script>");
        }

    }
}
